package edu.gatech.cs2340.sharks.fms;

/**
 * MainActivity.java
 * @author Matthew Schauer
 * 
 * The entry point of the program, which displays a splash screen and then opens the login activity
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import edu.gatech.cs2340.sharks.fms.data.DBMgr;

public class MainActivity extends Activity
{
	/**
	 * The length of time for which to display the splash screen
	 */
	private static final int splashTime = 2000; // 2 seconds
	
	/**
	 * The current instance of the activity, used to make sure there is only one instance of this activity running at a time.
	 */
	private static Activity instance = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		
		if (instance != null) instance.finish();
		instance = this;
		
		Handler splashHandler = new Handler();
		splashHandler.postDelayed(new SplashRunnable(this), splashTime);
		
		DBMgr.context = this;
	}
	private class SplashRunnable implements Runnable
	{
		private Activity activity;
		public SplashRunnable(Activity a)
		{
			activity = a;
		}
		public void run()
		{
			Intent toLogIn = new Intent(activity, LoginActivity.class);
			startActivity(toLogIn);
			finish();
		}
	}
}
